// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import '@/styles/index.scss'
import store from '@/store/store.js'
Vue.config.productionTip = false
// 添加全局路由守卫
router.beforeEach((to, from, next) => {
  var token = localStorage.getItem('mytoken')
  // 如果有token值,则next
  if (token) {
    next()
  } else {
    // 如果没有token，判断是否有to到login，有则next
    // console.log(to)
    if (to.path === '/login') {
      next()
    } else {
      // 跳转到login页面
      next({name: 'Login'})
    }
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
